﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General


Namespace DoAnQuanLyBanHang.DTO
    Public Class NhaCungCapData
        Private m_NhaCungCapData As New DataService()
        Public Function LayNhaCungCap() As DataTable
            Dim cmd As New SqlCommand("SELECT * FROM Nha_Cung_Cap")
            m_NhaCungCapData.Load(cmd)
            Return m_NhaCungCapData
        End Function

        Public Function ThemDongMoi() As DataRow
            Return m_NhaCungCapData.NewRow()
        End Function

        Public Sub ThemNhaCungCap(m_Row As DataRow)
            m_NhaCungCapData.Rows.Add(m_Row)
        End Sub

        Public Function LuuNhaCungCap() As Boolean
            Return m_NhaCungCapData.ExecuteNoneQuery() > 0
        End Function
        Public Sub LuuNhaCungCap(mancc As [String], tenncc As [String], dienthoai As [String], fax As [String], email As [String], diachi As [String], _
         ghichu As [String])
            Dim cmd As New SqlCommand("INSERT INTO Nha_Cung_Cap VALUES(@MaNCC, @TenNCC, @DienThoai, @Fax,  @Email, @DiaChi, @GhiChu)")
            cmd.Parameters.Add("MaNCC", SqlDbType.VarChar).Value = mancc
            cmd.Parameters.Add("TenNCC", SqlDbType.NVarChar).Value = tenncc
            cmd.Parameters.Add("DienThoai", SqlDbType.VarChar).Value = dienthoai
            cmd.Parameters.Add("Fax", SqlDbType.VarChar).Value = fax
            cmd.Parameters.Add("Email", SqlDbType.VarChar).Value = email
            cmd.Parameters.Add("DiaChi", SqlDbType.NVarChar).Value = diachi
            cmd.Parameters.Add("GhiChu", SqlDbType.NVarChar).Value = ghichu

            m_NhaCungCapData.Load(cmd)
        End Sub

        Public Sub SuaNhaCungCap(mancc As [String], tenncc As [String], dienthoai As [String], fax As [String], email As [String], diachi As [String], _
         ghichu As [String])
            Dim cmd As New SqlCommand("UPDATE Nha_Cung_Cap SET TenNCC = @TenNCC, DienThoai = @DienThoai, Fax = @Fax, Email = @Email, DiaChi = @DiaChi, GhiChu = @GhiChu WHERE MaNCC = @MaNCC")
            cmd.Parameters.Add("MaNCC", SqlDbType.VarChar).Value = mancc
            cmd.Parameters.Add("TenNCC", SqlDbType.NVarChar).Value = tenncc
            cmd.Parameters.Add("DienThoai", SqlDbType.VarChar).Value = dienthoai
            cmd.Parameters.Add("Fax", SqlDbType.VarChar).Value = fax
            cmd.Parameters.Add("Email", SqlDbType.VarChar).Value = email
            cmd.Parameters.Add("DiaChi", SqlDbType.NVarChar).Value = diachi
            cmd.Parameters.Add("GhiChu", SqlDbType.NVarChar).Value = ghichu
            m_NhaCungCapData.Load(cmd)
        End Sub

        Public Sub XoaNhaCungCap(mancc As [String])
            Dim cmd As New SqlCommand("DELETE FROM Nha_Cung_Cap WHERE MaNCC = @MaNCC")
            cmd.Parameters.Add("MaNCC", SqlDbType.VarChar).Value = mancc

            m_NhaCungCapData.Load(cmd)
        End Sub

#Region "tim kiem"
        Public Function TimKiemTheoMa(id As [String]) As DataTable
            Dim cmd As New SqlCommand("SELECT * FROM Nha_Cung_Cap WHERE MaNCC LIKE '%' + @id + '%'")
            cmd.Parameters.Add("id", SqlDbType.VarChar).Value = id

            m_NhaCungCapData.Load(cmd)
            Return m_NhaCungCapData
        End Function

        Public Function TimKiemTheoTen(ten As [String]) As DataTable
            Dim cmd As New SqlCommand("SELECT * FROM Nha_Cung_Cap WHERE TenNCC LIKE '%' + @ten + '%'")
            cmd.Parameters.Add("ten", SqlDbType.NVarChar).Value = ten

            m_NhaCungCapData.Load(cmd)
            Return m_NhaCungCapData
        End Function



#End Region
    End Class
End Namespace
